package com.sjj.shopping.service;

import com.sjj.shopping.MultipartFileToFile;
import net.sourceforge.tess4j.ITesseract;
import net.sourceforge.tess4j.Tesseract;
import net.sourceforge.tess4j.TesseractException;
import org.apache.dubbo.common.utils.StringUtils;
import org.springframework.web.multipart.MultipartFile;

/**
 * className:common
 * Package:com.sjj.shopping.service
 * Description:
 *
 * @Date: 2022/8/14 16:22
 * @Auther: wssky19890629@163.com
 */

public class Common {
    public static String imgToId(MultipartFile img) throws Exception {
        String lagnguagePath = "E:\\123";
        ITesseract instance = new Tesseract();
        instance.setDatapath(lagnguagePath);
        instance.setLanguage("chi_sim");
        String result = null;
        try {
            long startTime = System.currentTimeMillis();
            result =  instance.doOCR(MultipartFileToFile.multipartFileToFile(img)); //MultipartFileToFile类在下方
            long endTime = System.currentTimeMillis();
            System.out.println("Time is：" + (endTime - startTime) + " 毫秒");
        } catch (TesseractException e) {
            e.printStackTrace();
        }
        String answer = result.substring(result.length() - 19, result.length());
        System.out.println(answer);

        return answer;


    }
}
